<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item> <i class="el-icon-setting"></i> 过滤分配 </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="handle-box">
        <div style="margin-top: 15px">
          <el-input v-model="query.kw" placeholder="请输入用户名/电话查询" class="handle-input mr10"></el-input>
          <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
        </div>
      </div>
      <div class="text item" v-loading="loadingTeam">
        <el-form ref="form" :inline="true" label-width="100px">
          <el-form-item v-for="(item,i) in teamArr" :key="item.teamId" :label="item.teamName">
            <el-input type="number" v-model="item.value" placeholder="请输入"></el-input>
          </el-form-item>
          <el-row style="text-align: center">
            <el-form-item>
              <el-button type="primary" @click="saveMenuList">保存</el-button>
            </el-form-item>
          </el-row>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import {
  RolePermissionsQX,
  teamTeamCallList,
  teamUpdateTeamCall
} from '../../../api/index';
export default {
  data() {
    return {
      loadingTeam: false,
      teamArr: [],
      query: {
        kw:''
      }
    };
  },
  created() {
    this.threeLevels();
    this.handleSearch()
  },
  components: {
    
  },

  methods: {
    handleSearch(){
      this.loadingTeam = true;
      teamTeamCallList({teamName:this.query.kw}).then(res => {
        this.loadingTeam = false;
        if (res.code === 0) {
          this.teamArr = res.list
        }
        console.log(res);
      })
    },
    saveMenuList(){
      this.loadingTeam = true;
      let arr = [];
      this.teamArr.forEach((item) => {
        arr.push({
          teamId: item.teamId,
          teamName: item.teamName,
          value: item.value,
        })
      })
      teamUpdateTeamCall({ records: arr}).then((res) => {
        this.loadingTeam = false;
        if (res.code === 0) {
          this.$message.success("设置成功");
        } else {
          this.$message(res.msg);
        }
      });
      
    },
    //三级权限
    threeLevels() {
      let parentRouth = this.$route.path.replace('/', '');
      RolePermissionsQX({ urlName: parentRouth }).then((res) => {
        console.log(res);
        
        if (res.code === 0) {
          res.buttons.forEach((item, i) => {
            switch (item.name) {
              case '人员权重':
                this.threeLevelsbool.nameRole = item.pageIsShow;
                break;
              case '人员自动分配方式':
                this.threeLevelsbool.type = item.pageIsShow;
                break;
              case '部门权重':
                this.threeLevelsbool.nameRole_bu = item.pageIsShow;
                break;
              case '部门自动分配方式':
                this.threeLevelsbool.type_bu = item.pageIsShow;
                break;
              case '门店权重':
                this.threeLevelsbool.nameRole_men = item.pageIsShow;
                break;
              case '门店自动分配方式':
                this.threeLevelsbool.type_men = item.pageIsShow;
                break;
            }
          });
        } else {
          this.$message(res.msg);
        }
      });
    }
  }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}
.handle-input {
    width: 300px;
    display: inline-block;
}
.mr10 {
    margin-right: 10px;
}
</style>
